package com.crrc.dataparse.base.exception;

import com.crrc.dataparse.base.exception.Error.ExceptionNode;
import com.crrc.dataparse.base.exception.Error.ExceptionType;


public class RSPException extends Exception {
    private static final long serialVersionUID = 1L;
    private String rawDataId;
    private boolean shouldAbandon = false;
    private ExceptionNode node;
    private ExceptionType type;
    private String customMsg;
    private Exception ept;

    public RSPException() {
    }

    public RSPException(String customMsg) {
        super(customMsg);
        this.customMsg = customMsg;
    }

    public RSPException(String customMsg, Exception e) {
        super(customMsg, e);
        this.customMsg = customMsg;
        this.ept = e;
    }

    public RSPException(String customMsg, ExceptionType type, boolean shouldAbandon) {
        this.customMsg = customMsg;
        this.type = type;
        this.shouldAbandon = shouldAbandon;
    }

    public RSPException(String customMsg, String rawDataId, ExceptionType type, ExceptionNode node, boolean shouldAbandon) {
        this.customMsg = customMsg;
        this.rawDataId = rawDataId;
        this.node = node;
        this.type = type;
        this.shouldAbandon = shouldAbandon;
    }

    public String getCustomMsg() {
        return this.customMsg;
    }

    public Exception getException() {
        return this.ept;
    }

    public String getRawDataId() {
        return this.rawDataId;
    }

    public void setRawDataId(String rawDataId) {
        this.rawDataId = rawDataId;
    }

    public boolean isShouldAbandon() {
        return this.shouldAbandon;
    }

    public void setShouldAbandon(boolean shouldAbandon) {
        this.shouldAbandon = shouldAbandon;
    }

    public ExceptionNode getNode() {
        return this.node;
    }

    public void setNode(ExceptionNode node) {
        this.node = node;
    }

    public ExceptionType getType() {
        return this.type;
    }

    public void setType(ExceptionType type) {
        this.type = type;
    }

    public void handle(String msg) throws RSPException {
        if (this.shouldAbandon) {
            throw this;
        } else {
            System.out.println("错误数据包ID：" + this.rawDataId + " " + msg);
        }
    }

    public void handle() throws RSPException {
        this.handle((String)null);
    }
}
